package com.example.controller;

import com.example.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 代码练习僧
 * @since 2025-04-02
 */
@Controller
@RequestMapping("/book")
public class BookController {

    @Autowired
    private IBookService bookService;

    @ResponseBody
    @GetMapping("/{id}")
    public Object getBookById(@PathVariable int id) {
        return bookService.getById(id);
    }

    @ResponseBody
    @PostMapping("/byName")
    public Object getBookByName(String bookName) {
        return bookService.getBooksByName(bookName);
    }

    @ResponseBody
    @PostMapping("/byAuthor")
    public Object getBookByAuthor(String author) {
        return bookService.getBookByAuthor(author);
    }
}
